package com.wangyf.thread.c_000_whatisthread;

import java.util.concurrent.TimeUnit;

/**
 * 体会线程交替执行: 打印出来 交替进行
 * @author wangyf
 * @date 2021/1/1 11:19
 */
public class T01_WhatisThread {
    public static void main(String[] args) throws InterruptedException {
        new MyThread().start();
        new Thread(new Runnable() {
            public void run() {
                System.out.println();
            }
        });

        for (int i = 0; i < 10; i++) {
            TimeUnit.MICROSECONDS.sleep(1);
            System.out.println("main");
        }
    }

    private static class MyThread extends Thread{
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                try {
                    TimeUnit.MICROSECONDS.sleep(1);
                    System.out.println("T1");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

